<?php
//Open classlist. Populate an array with their names.
$file = "../data/Configurations/classlist.txt";
$fr=fopen($file,'r');
$s=0;
while(!feof($fr)){
	$str=trim(fgets($fr));
	if(strcmp($str,"") != 0 && substr($str,0,1) != "#"){
		$array[$s]=$str;
		$s++;
	}
}
fclose($fr);
//Build a student array and cycle through all the classes, filling the array with 
//the student names.
$students[0][0]="";
for($i=0; $i<$s; $i++){
	$file="../data/Classes/" . trim($array[$i] . "/passwords.txt");
	$j=0;
	$fr=fopen($file,'r');
	while(!feof($fr)){
		$string=trim(fgets($fr));
		$pos=stripos($string,",");
		$sub=substr($string,0,$pos);
		$sub=trim($sub);
		if(strcmp($sub,"") != 0){
			$students[$i][$j]=$sub;
			$j++;
		}
	}
}
//Return as a javascript two dimensional arrays.
$result=json_encode($students);
?>